#include <stdio.h>

#include "proteindata.h"

using namespace PBVP;

ChainData::ChainData(char id, PBVP::ProteinData *pProtein)
: m_Id(id)
{
	m_pProtein = pProtein;
}

QVector<Atom> ChainData::getAtoms()
{
	return m_Atoms;
}

void ChainData::addResidue(const QString& resName)
{
	int resId = ResidueInfo::lookupAAId(resName);
	m_Residues.append(resId);
}

void ChainData::addAtom(const Atom& atom)
{
	m_Atoms.append(atom);
}

void ChainData::print() const 
{
	printf("Chain %c :\n", m_Id);
	printf("	# of atoms = %d\n", numOfAtoms());
	printf("	# of residues = %d\n", numOfResidues());
}

QList<Atom> ChainData::getBackboneAtoms() const
{
	QList<Atom> backbone;
	// The first 4 atoms (N, CA, C, O) in each AA are backbone atoms ?
	
	int resCount = 0, curResId = 0, atomCount = 0;
	while(resCount < numOfResidues() && atomCount < numOfAtoms()) {
		Atom atom = m_Atoms[atomCount]; atomCount ++;
		if(atom.residueIndex != curResId) {	// first atom in the AA
			// backbone.push_back(atom);
			curResId = atom.residueIndex;
			resCount ++;
			// add next three atoms // only add CA atom ?
			backbone.push_back(m_Atoms[atomCount]); atomCount ++;
			// backbone.push_back(m_Atoms[atomCount]); atomCount ++;
			// backbone.push_back(m_Atoms[atomCount]); atomCount ++;
		}
	}
	// TODO

	return backbone;
}

LigandData::LigandData(const QString& _name, ProteinData *pProtein)
: m_Name(_name)
{
	m_pProtein = pProtein;
}

QVector<Atom> LigandData::getAtoms()
{
	return m_Atoms;
}

void LigandData::addAtom(const Atom& atom)
{
	m_Atoms.append(atom);
}

void LigandData::print() const 
{
	printf("Ligand %s :\n", name().toAscii().data());
	printf("	# of atoms = %d\n", numOfAtoms());
}